package config

type Config struct {
	Mode      Mode      `mapstructure:"mode"`
	Http      Http      `mapstructure:"http"`
	Redis     Redis     `mapstructure:"redis"`
	Limit     Limit     `mapstructure:"limit"`
	Cors      Cors      `mapstructure:"cors"`
	Gorm      Gorm      `mapstructure:"gorm"`
	Mysql     Mysql     `mapstructure:"mysql"`
	JWT       JWT       `mapstructure:"jwt"`
	AppletKey AppletKey `mapstructure:"applet_key"`
	Email     Email     `mapstructure:"email"`
}

type Mode struct {
	RunMode string `mapstructure:"run_mode"`
}

type Http struct {
	Host string `mapstructure:"host"`
	Port string `mapstructure:"port"`
}

type Redis struct {
	Addr     string `mapstructure:"addr"`
	Password string `mapstructure:"password"`
}

type Limit struct {
	Limit int64 `mapstructure:"limit"`
}

type Cors struct {
	Enable           bool          `mapstructure:"enable"`
	AllowOrigins     []interface{} `mapstructure:"allow_origins"`
	AllowMethods     []interface{} `mapstructure:"allow_methods"`
	AllowHeaders     []interface{} `mapstructure:"allow_headers"`
	AllowCredentials bool          `mapstructure:"allow_credentials"`
	MaxAge           int           `mapstructure:"max_age"`
}

type Gorm struct {
	Debug  bool   `mapstructure:"debug"`
	DBType string `mapstructure:"dbtype"`
}

type Mysql struct {
	Host     string `mapstructure:"host"`
	Port     string `mapstructure:"port"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
	Database string `mapstructure:"database"`
	Config   string `mapstructure:"config"`
}

func Dsn(m Mysql) string {
	return m.Username + ":" + m.Password + "@tcp(" + m.Host + ":" + m.Port + ")/" + m.Database + "?" + m.Config
}

type JWT struct {
	Key     string `mapstructure:"key"`
	Issuer  string `mapstructure:"issuer"`
	Expires int64  `mapstructure:"expires"`
}

type AppletKey struct {
	AppId  string `mapstructure:"appid"`
	Secret string `mapstructure:"secret"`
}

type Email struct {
	Host     string `mapstructure:"host"`
	Smtp     string `mapstructure:"smtp"`
	Addr     string `mapstructure:"addr"`
	Name     string `mapstructure:"name"`
	Password string `mapstructure:"password"`
	Expires  int    `mapstructure:"expires"`
}
